package cn.edu.hbsi.web.controller;

import cn.edu.hbsi.domain.dto.PublishDTO;
import cn.edu.hbsi.domain.dto.UpdateHeadlineDTO;
import cn.edu.hbsi.domain.result.Result;
import cn.edu.hbsi.service.HeadlineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 头条模块
 */
@RestController
@RequestMapping("/headline")
@Slf4j
@Api(tags = "头条模块相关接口")
public class HeadlineController
{
    @Autowired
    private HeadlineService headlineService;

    /**
     * 头条发布功能
     * @param token
     * @param publishDTO
     * @return
     */
    @ApiOperation("头条发布功能")
    @PostMapping("/publish")
    public Result publish(@RequestHeader String token, @RequestBody PublishDTO publishDTO){
        log.info("发布新闻参数：{}", publishDTO);
        return headlineService.publish(token, publishDTO);
    }

    /**
     * 修改新闻回显
     * @param hid
     * @return
     */
    @ApiOperation("修改头条回显")
    @PostMapping("/findHeadlineByHid")
    public Result findHeadlineByHid(@RequestParam("hid") Integer hid){
        log.info("修改新闻参数：{}", hid);
        return headlineService.findHeadlineByHid(hid);
    }

    /**
     * 修改新闻
     * @param updateHeadlineDTO
     * @return
     */
    @ApiOperation("修改新闻")
    @PostMapping("/update")
    public Result update(@RequestBody UpdateHeadlineDTO updateHeadlineDTO){
        log.info("修改新闻参数：{}", updateHeadlineDTO);
        return headlineService.updateHeadline(updateHeadlineDTO);
    }

    /**
     * 删除新闻功能
     * @param hid
     * @return
     */
    @ApiOperation("删除头条功能")
    @PostMapping("/removeByHid")
    public Result removeByHid(@RequestParam("hid") Integer hid){
        log.info("删除新闻参数：{}", hid);
        headlineService.removeById(hid);
        return Result.ok();
    }
}
